import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  page = "/auth-service/oauth2/client/page",
  listHistoryClient = "/auth-service/oauth2/client/listHistory",
  getByClientId = "/auth-service/oauth2/client/getByClientId",
  getById = "/auth-service/oauth2/client/get",
  getSecret = "/auth-service/oauth2/client/getSecret",
  settingSecret = "/auth-service/oauth2/client/settingSecret",
  list = "/auth-service/oauth2/client/list",
  listExtLdpConn = "/auth-service/oauth2/client/listExtLdpConn",
  save = "/auth-service/oauth2/client/save",
  edit = "/auth-service/oauth2/client/updateById",
  delete = "/auth-service/oauth2/client/deleteById",
  deleteBatch = "/auth-service/oauth2/client/deleteBatch",
  refreshCache = "/auth-service/oauth2/client/refreshCache",
}

export const pageClient = (params) => {
  return defHttp.get({ url: Api.page, params })
}
export const listHistoryClient = (params) => {
  return defHttp.get({ url: Api.listHistoryClient, params })
}

export const getByClientId = (params) => {
  return defHttp.get({ url: Api.getByClientId, params })
}
export const getSecret = (params) => {
  return defHttp.get({ url: Api.getSecret, params })
}
export const getById = (params) => {
  return defHttp.get({ url: Api.getById, params })
}
export const settingSecret = (params) => {
  return defHttp.post({ url: Api.settingSecret, params })
}

export const listClient = (params) => {
  return defHttp.get({ url: Api.list, params })
}

export const listExtLdpConn = (params) => {
  return defHttp.get({ url: Api.listExtLdpConn, params })
}

export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save
  return defHttp.post({ url: url, params })
}

export const refreshCache = () => {
  return defHttp.get({ url: Api.refreshCache })
}

export const deleteOauthClient = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteOauthClient = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
